| tle: “Mapping Census Data” |
| thor: “Enoch Shin and Felix Stetsenko” |
| te: “December 05, 2019” |
| tput: |
| html_document: |
| df_print: paged |
After we’ve ingested the tract-level census data and queried the Valentine’s Day data, we’ll do some preliminary analyses to explore plotting on Leaflet.
valday <- readRDS("ChicagoCommute/RDA/valday.Rda")
valday %<>% mutate_at(c("pickup_centroid_latitude", "pickup_centroid_longitude"), as.numeric)
names(valday)
## [1] "trip_id"
## [2] "trip_start_timestamp"
## [3] "trip_end_timestamp"
## [4] "trip_seconds"
## [5] "trip_miles"
## [6] "pickup_community_area"
## [7] "dropoff_community_area"
## [8] "fare"
## [9] "tip"
## [10] "additional_charges"
## [11] "trip_total"
## [12] "shared_trip_authorized"
## [13] "trips_pooled"
## [14] "pickup_centroid_latitude"
## [15] "pickup_centroid_longitude"
## [16] "pickup_centroid_location.type"
## [17] "pickup_centroid_location.coordinates"
## [18] "dropoff_centroid_latitude"
## [19] "dropoff_centroid_longitude"
## [20] "dropoff_centroid_location.type"
## [21] "dropoff_centroid_location.coordinates"
## [22] "dropoff_census_tract"
## [23] "pickup_census_tract"
race <- readRDS("ChicagoCommute/RDA/raceByTract.Rda")
income <- readRDS("ChicagoCommute/RDA/incomeByTract.Rda")
Get the shapefile for Cook County, which is where Chicago is located.
shapefile <- tigris::tracts(state = "17", county = "031")
shapefile_race <- geo_join(shapefile, race,"TRACTCE", "tract", how="left")
# poly <- fortify(shapefile)
# ggmap(get_map("Chicago, IL", zoom=9, color="bw"), extent="device") +
# geom_polygon(aes(x = long, y = lat, group = group),
# data = poly, colour = 'blue',
# alpha = .4, size = .3)
# install.packages("leaflet.providers")
# load additional tile providers
library(leaflet.providers)
#make the palette
palette <- colorNumeric(
palette="YlGnBu",
domain = shapefile_race$Black.or.African.American
)
# make base map
base <- leaflet(leafletOptions(preferCanvas = TRUE)) %>%
addProviderTiles(providers$CartoDB.Positron,
options = providerTileOptions(
updateWhenZooming = FALSE, # map won't update tiles until zoom is done
updateWhenIdle = TRUE)) %>%
addPolygons(data=shapefile_race, color="grey", weight=1); base
# add in black population
with_black <- base %>%
#note: should probably do this based on proportion in tract
addPolygons(data=shapefile_race,
fillColor=~palette(Black.or.African.American),
stroke=FALSE) %>%
addLegend(
pal = palette,
values = shapefile_race$Black.or.African.American,
position = "bottomright",
title = "Population of
Black/African American Persons"
); with_black